room.js ➔ updateCurrentSettings   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
eloc 5
1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
// Room specific js for copy button and email link.
18
$(document).on('turbolinks:load', function(){
19
  var controller = $("body").data('controller');
20
  var action = $("body").data('action');
21
22
  // Only run on room pages.
23
  if (controller == "rooms" && action == "show"){
24
    var copy = $('#copy');
25
26
    // Handle copy button.
27
    copy.on('click', function(){
28
      var inviteURL = $('#invite-url');
29
      inviteURL.select();
30
31
      var success = document.execCommand("copy");
32
      if (success) {
33
        inviteURL.blur();
34
        copy.addClass('btn-success');
35
        copy.html("<i class='fas fa-check'></i>" + getLocalizedString("copied"))
36
        setTimeout(function(){
37
          copy.removeClass('btn-success');
38
          copy.html("<i class='fas fa-copy'></i>" + getLocalizedString("copy"))
39
        }, 2000)
40
      }
41
    });
42
43
    // Forces the wrapper to take the entire screen height if the user can't create rooms
44
    if ($("#cant-create-room-wrapper").length){
45
      $(".wrapper").css('height', '100%').css('height', '-=130px');
46
    }
47
48
    // Display and update all fields related to creating a room in the createRoomModal
49
    $("#create-room-block").click(function(){
50
      showCreateRoom(this)
51
    })
52
53
    // Display and update all fields related to creating a room in the createRoomModal
54
    $(".update-room").click(function(){
55
      showUpdateRoom(this)
56
    })
57
58
    $(".delete-room").click(function() {
59
      showDeleteRoom(this)
60
    })
61
  }
62
});
63
64
function showCreateRoom(target) {
65
  var modal = $(target)
0 ignored issues
show
Unused Code introduced by
The variable modal seems to be never used. Consider removing it.
Loading history...
66
  $("#create-room-name").val("")
67
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
68
  $("#room_access_code").val(null)
69
70
  $("#createRoomModal form").attr("action", $("body").data('relative-root'))
71
  $("#room_mute_on_join").prop("checked", false)
72
  $("#room_require_moderator_approval").prop("checked", false)
73
  $("#room_anyone_can_start").prop("checked", false)
74
  $("#room_all_join_moderator").prop("checked", false)
75
76
  //show all elements & their children with a create-only class
77
  $(".create-only").each(function() {
78
    $(this).show()
79
    if($(this).children().length > 0) { $(this).children().show() }
80
  })
81
82
  //hide all elements & their children with a update-only class
83
  $(".update-only").each(function() {
84
    $(this).attr('style',"display:none !important")
85
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
86
  })
87
}
88
89
function showUpdateRoom(target) {
90
  var modal = $(target)
91
  var room_block_uid = modal.closest("#room-block").data("room-uid")
92
  $("#create-room-name").val(modal.closest("tbody").find("#room-name h4").text())
93
  $("#createRoomModal form").attr("action", room_block_uid + "/update_settings")
94
95
  //show all elements & their children with a update-only class
96
  $(".update-only").each(function() {
97
    $(this).show()
98
    if($(this).children().length > 0) { $(this).children().show() }
99
  })
100
101
  //hide all elements & their children with a create-only class
102
  $(".create-only").each(function() {
103
    $(this).attr('style',"display:none !important")
104
    if($(this).children().length > 0) { $(this).children().attr('style',"display:none !important") }
105
  })
106
107
  updateCurrentSettings(modal.closest("#room-block").data("room-settings"))
108
  
109
  var accessCode = modal.closest("#room-block").data("room-access-code")
110
111
  if(accessCode){
112
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
113
    $("#room_access_code").val(accessCode)
114
  } else {
115
    $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
116
    $("#room_access_code").val(null)
117
  }
118
}
119
120
function showDeleteRoom(target) {
121
  $("#delete-header").text(getLocalizedString("modal.delete_room.confirm").replace("%{room}", $(target).data("name")))
122
  $("#delete-confirm").parent().attr("action", $(target).data("path"))
123
}
124
125
//Update the createRoomModal to show the correct current settings
126
function updateCurrentSettings(settings){
127
  //set checkbox
128
  $("#room_mute_on_join").prop("checked", settings.muteOnStart)
129
  $("#room_require_moderator_approval").prop("checked", settings.requireModeratorApproval)
130
  $("#room_anyone_can_start").prop("checked", settings.anyoneCanStart)
131
  $("#room_all_join_moderator").prop("checked", settings.joinModerator)
132
}
133
134
function generateAccessCode(){
135
  const accessCodeLength = 6
136
  var validCharacters = "0123456789"
137
  var accessCode = ""
138
139
  for( var i = 0; i < accessCodeLength; i++){
140
    accessCode += validCharacters.charAt(Math.floor(Math.random() * validCharacters.length));
141
  }
142
143
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code") + ": " + accessCode)
144
  $("#room_access_code").val(accessCode)
145
}
146
147
function ResetAccessCode(){
148
  $("#create-room-access-code").text(getLocalizedString("modal.create_room.access_code_placeholder"))
149
  $("#room_access_code").val(null)
150
}
151